package 蓝桥.模拟赛;

import java.util.Arrays;

public class Main5_3 {
    // 回溯
    int min = Integer.MAX_VALUE;

    void backtrace(int i, int[] nums, int sum) {
        if (i == nums.length) {
            if(sum%24==23 && sum<min){
                min = sum;
                System.out.println(min);
            }
            return;
        }
        backtrace(i + 1, nums, sum);
        if(nums[i]%24!=0)
            backtrace(i + 1, nums, sum + nums[i]);



    }

    public static void main(String[] args) {
        int[] nums = {534, 386, 319, 692, 169, 338, 521, 713, 640, 692, 969, 362, 311, 349, 308, 357, 515, 140, 591, 216,

                57, 252, 575, 630, 95, 274, 328, 614, 18, 605, 17, 980, 166, 112, 997, 37, 584, 64, 442, 495,

                821, 459, 453, 597, 187, 734, 827, 950, 679, 78, 769, 661, 452, 983, 356, 217, 394, 342, 697, 878,

                475, 250, 468, 33, 966, 742, 436, 343, 255, 944, 588, 734, 540, 508, 779, 881, 153, 928, 764, 703,

                459, 840, 949, 500, 648, 163, 547, 780, 749, 132, 546, 199, 701, 448, 265, 263, 87, 45, 828, 634};

        int sum = 0;
        for (int i : nums) {
            sum += i;
        }
        Arrays.sort(nums);
        // nums进行逆序
        for (int i = 0; i < nums.length / 2; i++) {
            int temp = nums[i];
            nums[i] = nums[nums.length - i - 1];
            nums[nums.length - i - 1] = temp;
        }
        System.out.printf("nums.length = %d\n", nums.length);
        System.out.printf("sum = %d\n", sum);

        int m = 35;
        // 将nums的后m个数新建一个数组
        int[] nums2 = new int[m];
        System.arraycopy(nums, nums.length - m, nums2, 0, m);

        Main5_3 t = new Main5_3();
        t.backtrace(0, nums2, 0);

    }
}
